package com.kwok.boot.rabbitmq.routing.producer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    // 1.创建一个路由交换机
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("Routing-Direct-Exchange");
    }

    // 2.创建两个队列
    @Bean
    public Queue queueOne(){
        return new Queue("Routing-Queue-One");
    }

    @Bean
    public Queue queueTwo(){
        return new Queue("Routing-Queue-Two");
    }

    // 3.通过方法名将两个队列分别和交换机进行绑定
    // 两个队列各自绑定了两个路由键
    @Bean
    public Binding bindingOne(){
        //将队列和交换机进行绑定并通过with方法给一个条件
        return BindingBuilder.bind(queueOne()).to(directExchange()).with("debug");
    }

    @Bean
    public Binding binding1(){
        //将队列和交换机进行绑定并通过with方法给一个条件
        return BindingBuilder.bind(queueOne()).to(directExchange()).with("info");
    }

    @Bean
    public Binding bindingTwo(){
        //将队列和交换机进行绑定并通过with方法给一个条件
        return BindingBuilder.bind(queueTwo()).to(directExchange()).with("warning");
    }

    @Bean
    public Binding binding2(){
        //将队列和交换机进行绑定并通过with方法给一个条件
        return BindingBuilder.bind(queueTwo()).to(directExchange()).with("error");
    }

}
